package com.situ.day6;

import org.junit.Test;

import java.util.Scanner;

public class HomeWork {

//    >=90    <=100    优秀
//     >=80    <90        良好
//    >=70    <80         一般
//    >=60    <70         及
//    <60                     不及格
    @Test
    public void test1() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入成绩：");
        int score = scanner.nextInt();
        if (score < 0 || score > 100) {
            System.out.println("成绩非法");
            return;
        }

        switch (score / 10) {
            case 10:
            case 9:
                System.out.println("优秀");
                break;
            case 8:
                System.out.println("良好");
                break;
            case 7:
                System.out.println("一般");
                break;
            case 6:
                System.out.println("及格");
                break;
            default:
                System.out.println("不及格");
                break;
        }
    }

    //能被4整除，但是不能被100整除    ||   能被400整除
    @Test
    public void test2() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入年份：");
        int year = scanner.nextInt();
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
            System.out.println(year + "是闰年");
        } else {
            System.out.println(year + "不是闰年");
        }
    }

    //2、从控制台输入两个数,然后分别打印这两个数，然后交换这两个数的值
    @Test
    public void test3() {
        int num1 = 3;
        int num2 = 5;
        int temp = num1;
        num1 = num2;
        num2 = temp;
        System.out.println("num1: " + num1);
        System.out.println("num2: " + num2);
    }

    @Test
    public void test5() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入单价：");
        double unitPrice = scanner.nextDouble();
        System.out.println("请输入数量: ");
        double count = scanner.nextDouble();
        System.out.println("请输入金额：");
        double price = scanner.nextDouble();
        double totalPrice = unitPrice * count;
        if (totalPrice >= 500) {
            //totalPrice = totalPrice * 0.8;
            totalPrice *= 0.8;
        }
        double returnPrice = price - totalPrice;
        if (returnPrice >= 0) {
            System.out.println("找零：" + returnPrice);
        } else {
            System.out.println("钱不够");
        }
    }

//    1
//    12
//    123
//    1234
//    12345
    @Test
    public void test6() {
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j);
            }
            System.out.println();
        }
    }

//    -----*
//    ----***
//    ---*****
//    --*******
//    -*********
//    ***********
    //i=1  j=1    j=5
    //i=2  j=3    j=4
    //i=3  j=5    j=3
    //i=4  j=7    j=2
    //j=2*i-1   i+j=6  j=6-i
    @Test
    public void test8() {
        for (int i = 1; i <= 6; i++) {
            for (int j = 1; j <= (6 - i); j++) {
                System.out.print("-");
            }

            for (int j = 1; j <= (2 * i - 1); j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    //计算1-100以内所有奇数的和以及所有偶数的和，分别打印出来。
    @Test
    public void test77() {
        int oddSum = 0;
        int evenSum = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                evenSum = evenSum + i;
            } else {
                oddSum = oddSum + i;
            }
        }
        System.out.println("奇数：" + oddSum);
        System.out.println("偶数：" + evenSum);
    }

    //用for循环输出1—1000之间能被5整除的数，且每行输出3个
    @Test
    public void test189(){
        int count = 0;
        for (int i = 1; i <= 1000; i++) {
            if (i % 5 == 0) {
                System.out.print(i + "\t");
                count++;
            }

            if (count == 3) {
                System.out.println();
                count = 0;
            }
        }
    }

    //计算9的阶乘
    //9!=9*8*7*6...*3*2*1
    @Test
    public void test999() {
        int sum = 1;
        for (int i = 9; i >= 1 ; i--) {
            //System.out.println("i: " + i);
            sum = sum * i;
        }
        System.out.println("sum: " + sum);
    }
}
